//
//  ZCTableViewCell.m
//  BaiSi
//
//  Created by 张灿 on 16/5/2.
//  Copyright © 2016年 张灿. All rights reserved.
//

#import "ZCAllViewCell.h"
#import "ZCTopView.h"
#import "ZCThemeItem.h"
#import "ZCThemeViewModel.h"
#import "ZCMiddleView.h"
#import "ZCVoiceView.h"
#import "ZCVideoView.h"
#import "ZCHotCommentView.h"
#import "ZCBottomView.h"


@interface ZCAllViewCell ()

@property (weak, nonatomic) ZCTopView *topView;

@property (weak, nonatomic) ZCMiddleView *middleView;

@property (weak, nonatomic) ZCVoiceView *voiceView;

@property (weak, nonatomic) ZCVideoView *videoView;

@property (weak, nonatomic) ZCHotCommentView *hotCommentView;

@property (weak, nonatomic) ZCBottomView *bottomView;

@end

@implementation ZCAllViewCell

- (void)setVm:(ZCThemeViewModel *)vm
{
    _vm = vm;
    
    _topView.frame = vm.topFrame;
    
    _topView.item = vm.item;
    
    //传数据进来时,要判断是否是图片类型,不是要隐藏
    if (vm.item.type == ZCThemeTypePicture) { //图片
        //显示图片
        _middleView.hidden = NO;
        
        _videoView.hidden = YES;
        
        _voiceView.hidden = YES;
        
        _middleView.frame = vm.middleFrame;
        
        _middleView.item = vm.item;
    } else if (vm.item.type == ZCThemeTypeVoice){ //声音
        //不是图片要隐藏
        _middleView.hidden = YES;
        
        _videoView.hidden = YES;
        
        _voiceView.hidden = NO;
        
        _voiceView.frame = vm.middleFrame;
        
        _voiceView.item = vm.item;
    }
    else if (vm.item.type == ZCThemeTypeVideo) { //视频
        _middleView.hidden = YES;
        _voiceView.hidden = YES;
        _videoView.hidden = NO;
        _videoView.frame = vm.middleFrame;
        _videoView.item = vm.item;
    } else { //都不是
        _middleView.hidden = YES;
        _voiceView.hidden = YES;
        _videoView.hidden = YES;
    }
    if (vm.item.commentItem) { //最热评论
        _hotCommentView.hidden = NO;
        _hotCommentView.frame = vm.hotFrame;
        _hotCommentView.item = vm.item;
    } else { //一定要记得,有显示就有隐藏
        _hotCommentView.hidden = YES;
    }
    _bottomView.frame = vm.bottomFrame;
    _bottomView.item = vm.item;
    
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        //添加顶部
        ZCTopView *topView = [ZCTopView topView];
        [self.contentView addSubview:topView];
        _topView = topView;
        
        //添加中间
        ZCMiddleView *middleView = [ZCMiddleView middleView];
        [self.contentView addSubview:middleView];
        _middleView = middleView;
        
        //添加声音View
        ZCVoiceView *voiceView = [ZCVoiceView viewFromXib];
        [self.contentView addSubview:voiceView];
        _voiceView = voiceView;
        
        //添加视频View
        ZCVideoView *videoView = [ZCVideoView viewFromXib];
        [self.contentView addSubview:videoView];
        _videoView = videoView;
        
        //添加最热评论
        ZCHotCommentView *hotCommentView = [ZCHotCommentView viewFromXib];
        [self.contentView addSubview:hotCommentView];
        _hotCommentView = hotCommentView;
        
        //添加底部点赞,踩,分享,评论
        ZCBottomView *bottomView = [ZCBottomView viewFromXib];
        [self.contentView addSubview:bottomView];
        self.bottomView = bottomView;
        
        
    }
    return self;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)setFrame:(CGRect)frame
{
    frame.size.height -=10;
    [super setFrame:frame];
}

@end
